package com.xgame.server.handler.impl;

import com.google.protobuf.InvalidProtocolBufferException;
import com.xgame.server.db.model.*;
import com.xgame.server.dbtool.*;
import com.xgame.server.handler.Handler;
import com.xgame.server.netty.enity.MsgEntity;
import com.xgame.server.netty.proto.Cmdcode;
import com.xgame.server.netty.proto.Game;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.regex.Pattern;

@Component
public class LoginHandler implements Handler {

    private static final Logger logger = LoggerFactory.getLogger(LoginHandler.class);

    @Resource
    private GameUtilTool gameUtilTool;

    @Resource
    private AccountCsTool accountCsTool;

    @Resource
    private AccountrecordCsTool accountrecordCsTool;

    @Resource
    private BagCsTool bagCsTool;

    @Resource
    private BossrankCsTool bossrankCsTool;

    @Resource
    private BossspawnCsTool bossspawnCsTool;

    @Resource
    private CopymapCsTool copymapCsTool;

    @Resource
    private EnrollrefreshCsTool enrollrefreshCsTool;

    @Resource
    private EquipCsTool equipCsTool;

    @Resource
    private GamecfgCsTool gamecfgCsTool;

    @Resource
    private GamerecordCsTool gamerecordCsTool;

    @Resource
    private HeroCsTool heroCsTool;

    @Resource
    private HeroitemCsTool heroitemCsTool;

    @Resource
    private HeroskillCsTool heroskillCsTool;

    @Resource
    private HeroGongCsTool heroGongCsTool;

    @Resource
    private RolespawnCsTool rolespawnCsTool;

    @Resource
    private ShoprefreshCsTool shoprefreshCsTool;

    @Resource
    private TasklistCsTool tasklistCsTool;

    @Resource
    private AccountillegalCsTool accountillegalCsTool;

    @Resource
    private GrowupwelfCsTool growupwelfCsTool;

    @Resource
    private PurgatoryCsTool purgatoryCsTool;

    @Resource
    private FuckiosCsTool fuckiosCsTool;

    @Override
    public void doHandler(MsgEntity msgEntity, List<MsgEntity> commandList) {

        if (msgEntity.getCmdCode() == (int) Cmdcode.LoginCmdCode.CS_LOGIN_REQ.getNumber()) {
            //1.请求登陆游戏，用来验证登陆账号是否正确
            try {
                Cmdcode.LoginReqCs req = loginSerialBytes2Object(msgEntity.getData());
                Integer result = accountCsTool.selectUserByAccountSize(req.getAccount(), req.getPwd());

                if (result == 1) {
                    //账号密码对应正确
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_LOGIN_RES.getNumber(), 99, 0, 1, 0);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                } else {
                    //账号或密码错误，返回错误代码：2
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_LOGIN_RES.getNumber(), 99, 0, 0, 2);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                }
            } catch (Exception e) {
                //遇到服务器异常，返回代码：1
                logger.error("line94:" + e.toString());
                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_LOGIN_RES.getNumber(), 99, 0, 0, 1);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
            }
        } else if (msgEntity.getCmdCode() == (int) Cmdcode.LoginCmdCode.CS_REGISTER_REQ.getNumber()) {
            //2.请求注册游戏账号
            try {

                Cmdcode.RegisterReqCs req = registerSerialBytes2Object(msgEntity.getData());
                logger.error("CIdentify:" + req.getIdentify());
                //校验绑定，如果在accountbind表中有已经存在identify的话，就提示设备绑定
                if (accountCsTool.checkIdentify(req.getIdentify())) {
                    //如果存在提示目前已经绑定了设备，无法去重新注册新的账号，此方法杜绝同一设备三卡重复创建进行出售，错误代码11
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 11);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                    return;
                }

                //首先检查是否符合正则式，账号：6~20位大小写数字，密码：6~20位大小写数字
                String pattern1 = "[A-Za-z0-9]{6,20}";
                String pattern2 = "[A-Za-z0-9]{6,20}";
                boolean matchAccount = Pattern.matches(pattern1, req.getAccount());
                boolean matchPwd = Pattern.matches(pattern2, req.getPwd());

                if (matchAccount && matchPwd) {
                    //检测是否账号已经存在
                    Integer result = accountCsTool.selectUserByAccountSize(req.getAccount());
                    if (result == 1) {
                        //已经存在注册码，返回代码：2
                        MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 2);
                        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                    } else {
                        Integer rrt = accountCsTool.insertUser(req.getAccount(), req.getPwd(), req.getIdentify());
                        if (rrt != 1) {
                            //插入数据失败，返回代码：3
                            MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 3);
                            msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                        } else {
                            //注册成功
                            MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 1, 0);
                            msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                        }
                    }
                } else if (!matchAccount && matchPwd) {
                    //账号不符合，错误代码：4
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 4);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                } else if (matchAccount && !matchPwd) {
                    //密码不符合，错误代码：5
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 5);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                } else {
                    //账号和密码不符合，错误代码：6
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 6);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                }
            } catch (Exception e) {
                //遇到服务器异常，返回代码：1
                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_REGISTER_RES.getNumber(), 99, 0, 0, 1);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
            }

        } else if (msgEntity.getCmdCode() == (int) Cmdcode.LoginCmdCode.CS_CHECK_REQ.getNumber()) {
            //3.请求检测账号的正确性
            try {
                Cmdcode.LoginReqCs req = loginSerialBytes2Object(msgEntity.getData());
                Integer result = accountCsTool.selectUserByAccountSize(req.getAccount(), req.getPwd());

                if (result == 1) {
                    //账号密码对应正确
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECK_RES.getNumber(), 99, 0, 1, 0);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                } else {
                    //账号或密码错误，返回错误代码：2
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECK_RES.getNumber(), 99, 0, 0, 2);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                }
            } catch (Exception e) {
                //遇到服务器异常，返回代码：1
                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECK_RES.getNumber(), 99, 0, 0, 1);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
            }
        } else if (msgEntity.getCmdCode() == (int) Cmdcode.LoginCmdCode.CS_CHECKDOWNLOAD_REQ.getNumber()) {
            //3.请求检测账号的正确性
            try {
                Cmdcode.LoginReqCs req = loginSerialBytes2Object(msgEntity.getData());
                Integer result = accountCsTool.selectUserByAccountSize(req.getAccount(), req.getPwd());

                if (result == 1) {
                    //账号密码对应正确
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECKDOWNLOAD_RES.getNumber(), 99, 0, 1, 0);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                } else {
                    //账号或密码错误，返回错误代码：2
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECKDOWNLOAD_RES.getNumber(), 99, 0, 0, 2);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                }
            } catch (Exception e) {
                //遇到服务器异常，返回代码：1
                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.LoginCmdCode.CS_CHECKDOWNLOAD_RES.getNumber(), 99, 0, 0, 1);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
            }
        } else if (msgEntity.getCmdCode() == (int) Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_REQ.getNumber()) {
            //4.请求下载游戏进度文件
            try {
                Cmdcode.CommonReqCs req = commonSerialBytes2Object(msgEntity.getData());
                if (req == null) {
                    logger.error("CommonReqCs Parse error!！");
                    return;
                }

                //首先检查是否是作弊
                if (accountCsTool.checkValidAccount(req.getAccount()) == false) {

                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_RES.getNumber(), 99, 0, 0, 1);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                    return;
                }

                //首先判断是否已经超过30天
                if (accountCsTool.checkRegisDays(req.getAccount(), 30) == false) {
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_RES.getNumber(), 99, 0, 0, 3);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                    return;
                }

                //首先判断数据库还原次数是否充足！
                if (accountCsTool.getOptionCount(req.getAccount()) >= 1) {
                    //已经达到了最大次数,错误代码：2
                    MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_RES.getNumber(), 99, 0, 0, 2);
                    msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
                    return;
                }

                handleAccountData(req.getAccount(), msgEntity);
                handleAccountrecordData(req.getAccount(), msgEntity);
                handleBagitemData(req.getAccount(), msgEntity);
                handleBossspawnData(req.getAccount(), msgEntity);
                handleCopymapData(req.getAccount(), msgEntity);
                handleEnrollrefreshData(req.getAccount(), msgEntity);
                handleEquipData(req.getAccount(), msgEntity);
                handleGamecfgData(req.getAccount(), msgEntity);
                handleGamerecordData(req.getAccount(), msgEntity);
                handleHeroData(req.getAccount(), msgEntity);
                handleRolespawnData(req.getAccount(), msgEntity);
                handleShopRefreshData(req.getAccount(), msgEntity);
                handleTasklistData(req.getAccount(), msgEntity);
                handleGrowupwelfData(req.getAccount(), msgEntity);
                handlePurgatoryData(req.getAccount(), msgEntity);
                handleIOSPurchaseyData(req.getAccount(), msgEntity);

                accountCsTool.updateOptionCount(req.getAccount());

                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_RES.getNumber(), 99, 0, 1, 0);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息

            } catch (Exception e) {
                System.out.print(e.getMessage());
                e.printStackTrace();
                MsgEntity resRt = gameUtilTool.getCommonResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAME_DOWNLOAD_RES.getNumber(), 99, 0, 0, 1);
                msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
            }
        }
    }

    //提取Account数据
    public void handleAccountData(String account, MsgEntity msgEntity) throws Exception {
        Game.AccountDataCS.Builder obj = Game.AccountDataCS.newBuilder();
        List<Account> data = accountCsTool.selectAccountByAccount(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + " not exist in account table!");
            throw new Exception();
        }

        Account act = data.get(0);

        obj.setAccount(account);
        obj.setPlayerID(act.getPlayerId());
        obj.setRoleName(act.getRoleName());
        obj.setLevel(act.getLevel());
        obj.setExp(act.getExp().intValue());
        obj.setCoin(act.getCoin());
        obj.setDiamond(act.getDiamond());
        obj.setIdentify(act.getIdentify());
        obj.setTotalRecharge(act.getTotalRecharge());
        obj.setValidDiamond(act.getValidDiamond());
        obj.setLimit(act.getLimit());
        obj.setCard1(act.getCard1());
        obj.setCard2(act.getCard2());
        obj.setCard3(act.getCard3());

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_ACCOUNT_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Accountrecord数据
    public void handleAccountrecordData(String account, MsgEntity msgEntity) throws Exception {
        Game.AccountRecordCS.Builder obj = Game.AccountRecordCS.newBuilder();
        obj.setAccount(account);

        List<Accountrecord> data = accountrecordCsTool.selectAccountRecord(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + " not exist in accountrecord table!");
        } else {
            Accountrecord act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setDiamondAdd(act.getDiamondAdd());
            obj.setDiamondAddVip(act.getDiamondAddVip());
            obj.setDiamondUse(act.getDiamondUse());
            obj.setDiamondUseVip(act.getDiamondUseVip());
            obj.setDiamondDayAdd(act.getDiamondDayAdd());
            obj.setDiamondDayAddVip(act.getDiamondDayAddVip());
            obj.setDiamondDayUse(act.getDiamondDayUse());
            obj.setDiamondDayUseVip(act.getDiamondDayUseVip());

            MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_ACCOUNTRECORD_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
            msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
        }
    }

    //提取Bag数据
    public void handleBagitemData(String account, MsgEntity msgEntity) throws Exception {
        Game.ItemCs.Builder obj = Game.ItemCs.newBuilder();
        obj.setAccount(account);

        List<Bagitem> data = bagCsTool.selectBagItems(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in bagitem table!");
        } else {
            for (int i = 0; i < data.size(); i++) {
                if (null == data.get(i)) {
                    continue;
                }
                Game.ItemOneCs.Builder one = Game.ItemOneCs.newBuilder();
                one.setGuid(data.get(i).getGuid());
                one.setItemId(data.get(i).getItemId());
                one.setNum(data.get(i).getNum());
                one.setEnhanceLv(data.get(i).getEnhanceLv());
                obj.setPlayerID(data.get(i).getPlayerId());

                obj.addArray(one.build());
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_BAG_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Bossrank数据<暂时不用>
    public void handleBossrankData(String account, MsgEntity msgEntity) throws Exception {
        Game.BossRankCS.Builder obj = Game.BossRankCS.newBuilder();
        obj.setAccount(account);

        List<Bossrank> data = bossrankCsTool.selectBossRank(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in bossrank table!");
        } else {
            Bossrank act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setRankValue(act.getRankValue());
            obj.setRewardId(act.getRewardId());
            obj.setLastRecord(act.getLastRecord());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_BOSSRANK_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Bossspawn数据
    public void handleBossspawnData(String account, MsgEntity msgEntity) throws Exception {
        Game.BossSpawnCS.Builder obj = Game.BossSpawnCS.newBuilder();
        obj.setAccount(account);

        List<Bossspawn> data = bossspawnCsTool.selectBossSpawn(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in bossspawn table!");
        } else {
            Bossspawn act = data.get(0);

            obj.setPlayerID(act.getPlayerId());

            for (int i = 0; i < data.size(); i++) {
                if (null == data.get(i)) {
                    continue;
                }
                Game.BossSpawnDataCS.Builder one = Game.BossSpawnDataCS.newBuilder();
                one.setInstId(data.get(i).getInstId().intValue());
                one.setChallengeCount(data.get(i).getChallengeCount());
                one.setBuyCount(data.get(i).getBuyCount());
                one.setIsOver(data.get(i).getIsOver() == 1);

                if (null != data.get(i).getDataList() && "" != data.get(i).getDataList()) {
                    String[] temp = data.get(i).getDataList().split("\\^");
                    for (int j = 0; j < temp.length; j++) {
                        if ("" == temp[j]) {
                            continue;
                        }
                        Game.BossSpawnDataOneCS.Builder ltt = Game.BossSpawnDataOneCS.newBuilder();
                        String[] temp2 = temp[j].split(";");
                        if (temp2.length != 2 || "" == temp2[0] || "" == temp2[1]) {
                            continue;
                        }
                        ltt.setLongId(Long.parseLong(temp2[0]));
                        ltt.setChallengeHp(Integer.parseInt(temp2[1]));
                        one.addList(ltt.build());
                    }
                }

                if (null != data.get(i).getBossRank() && "" != data.get(i).getBossRank()) {
                    String[] boss = data.get(i).getBossRank().split(";");
                    if (boss.length == 5 && "" != boss[0] && "" != boss[1] && "" != boss[2] && "" != boss[3] && "" != boss[4]) {
                        Game.BossRankCS.Builder ltt = Game.BossRankCS.newBuilder();
                        ltt.setAccount(boss[0]);
                        ltt.setPlayerID(boss[1]);
                        ltt.setRankValue(Integer.parseInt(boss[2]));
                        ltt.setRewardId(Integer.parseInt(boss[3]));
                        ltt.setLastRecord(Long.parseLong(boss[4]));
                        one.setBossRankCS(ltt.build());
                    }
                }
                obj.setWeekLastRecord(data.get(i).getWeekLastRecord());
                obj.addList(one.build());
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_BOSSSPAWN_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Copymap数据
    public void handleCopymapData(String account, MsgEntity msgEntity) throws Exception {
        Game.CopyMapCS.Builder obj = Game.CopyMapCS.newBuilder();
        obj.setAccount(account);

        List<Copymap> data = copymapCsTool.selectCopyMap(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in copymap table!");
        } else {
            Copymap act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            if ("" != act.getCompletedList() && null != act.getCompletedList()) {
                String[] temp = act.getCompletedList().split("\\^");
                for (int i = 0; i < temp.length; i++) {
                    if ("" == temp[i]) {
                        continue;
                    }
                    obj.addCompletedList(Integer.parseInt(temp[i]));
                }
            }

            obj.setCurrentMapId(act.getCurrentMapid());
            obj.setBuyTimes(act.getBuyTimes());
            obj.setExpTimes(act.getExpTimes());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_COPYMAP_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Enrollrefresh数据
    public void handleEnrollrefreshData(String account, MsgEntity msgEntity) throws Exception {
        Game.EnrollRefreshCS.Builder obj = Game.EnrollRefreshCS.newBuilder();
        obj.setAccount(account);

        List<Enrollrefresh> data = enrollrefreshCsTool.selectEnrollRefresh(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in enroll table!");
        } else {
            Enrollrefresh act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setIdentify(act.getIdentity());
            if (null != act.getData() && "" != act.getData()) {
                String[] temp = act.getData().split("\\^");
                for (int i = 0; i < temp.length; i++) {
                    if ("" == temp[i]) {
                        continue;
                    }
                    Game.EnrollRefreshOneCS.Builder one = Game.EnrollRefreshOneCS.newBuilder();
                    String[] temps = temp[i].split(";");
                    for (int j = 0; j < temps.length; j++) {
                        if (temps.length != 3 || "" == temps[0] || "" == temps[1] || "" == temps[2]) {
                            continue;
                        }

                        one.setType(Integer.parseInt(temps[0]));
                        one.setLastDieTime(Long.parseLong(temps[1]));
                        one.setSpawnInterval(Integer.parseInt(temps[2]));
                        obj.addList(one);
                    }
                }
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_ENROLLREFRESH_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Equip数据
    public void handleEquipData(String account, MsgEntity msgEntity) throws Exception {
        Game.EquipCs.Builder obj = Game.EquipCs.newBuilder();
        obj.setAccount(account);

        List<Equip> data = equipCsTool.selectEquipByAccount(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in equip table!");
        } else {
            for (int i = 0; i < data.size(); i++) {
                if (null == data.get(i)) {
                    continue;
                }
                Game.EquipOneCs.Builder one = Game.EquipOneCs.newBuilder();
                obj.setPlayerID(data.get(i).getPlayerId());
                one.setGuid(data.get(i).getGuid());
                one.setItemId(data.get(i).getItemId());
                one.setEatID(data.get(i).getEatId());
                one.setEatLevel(data.get(i).getEatLevel());
                one.setEatExp(data.get(i).getEatExp().intValue());
                one.setQuality(data.get(i).getQuality());

                if (null != data.get(i).getQualityList() && "" != data.get(i).getQualityList()) {

                    String[] lst = data.get(i).getQualityList().split("\\^");
                    for (int j = 0; j < lst.length; j++) {
                        if ("" == lst[j]) {
                            continue;
                        }

                        one.addQualityList(Integer.parseInt(lst[j]));
                    }
                }
                one.setDemonLv(data.get(i).getDemonLv());
                one.setDemonExp(data.get(i).getDemonExp().intValue());

                if (null == data.get(i).getIsLock()) {
                    one.setIsLock(0);
                } else {
                    one.setIsLock(data.get(i).getIsLock());
                }

                if (null == data.get(i).getHasSeal()) {
                    one.setHasSeal(0);
                } else {
                    one.setHasSeal(data.get(i).getHasSeal());
                }

                if (null == data.get(i).getLastSealTime()) {
                    one.setLastSealTime(0);
                } else {
                    one.setLastSealTime(data.get(i).getLastSealTime());
                }

                if (null != data.get(i).getSealList() && "" != data.get(i).getSealList()) {

                    String[] lst = data.get(i).getSealList().split("\\^");
                    for (int j = 0; j < lst.length; j++) {
                        if ("" == lst[j]) {
                            continue;
                        }

                        String[] lst2 = lst[j].split("\\*");

                        if (lst2.length == 2) {
                            Game.SealValue.Builder two = Game.SealValue.newBuilder();
                            two.setSealId(Integer.parseInt(lst2[0]));
                            two.setSealValue(Float.parseFloat(lst2[1]));
                            one.addSealList(two);
                        }
                    }
                }

                obj.addArray(one.build());
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_EQUIP_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Gamecfg数据
    public void handleGamecfgData(String account, MsgEntity msgEntity) throws Exception {
        Game.GameCfgCS.Builder obj = Game.GameCfgCS.newBuilder();
        obj.setAccount(account);

        List<Gamecfg> data = gamecfgCsTool.selectGameCfg(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in gamecfg table!");
        } else {
            Gamecfg act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setIdentify(act.getIdentity());
            obj.setIsEntered(act.getIsEntered() == 1 ? true : false);
            obj.setFirstRecord(act.getFirstRecord());
            obj.setLastRecord(act.getLastRecord());
            obj.setOpflag(act.getOpFlag().intValue());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAMECFG_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Gamerecord数据
    public void handleGamerecordData(String account, MsgEntity msgEntity) throws Exception {
        Game.GameRecordCS.Builder obj = Game.GameRecordCS.newBuilder();
        obj.setAccount(account);

        List<Gamerecord> data = gamerecordCsTool.selectGameRecord(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in gamerecord table!");
        } else {

            int length = data.size();
            for (int i = 0; i < length; i++) {
                if (null == data.get(i)) {
                    continue;
                }
                Game.GameRecordOneCS.Builder one = Game.GameRecordOneCS.newBuilder();
                one.setOp(data.get(i).getOp().intValue());
                one.setCoin(data.get(i).getCoin());
                one.setDiamond(data.get(i).getDiamond());
                one.setMsg(data.get(i).getMsg());
                one.setTime(data.get(i).getTime());
                obj.setPlayerID(data.get(i).getPlayerId());

                obj.addList(one.build());
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GAMERECORD_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Hero数据
    public void handleHeroData(String account, MsgEntity msgEntity) throws Exception {
        Game.HeroDataCS.Builder obj = Game.HeroDataCS.newBuilder();
        obj.setAccount(account);

        List<Hero> data = heroCsTool.selectHero(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in hero table!");
        } else {

            int length = data.size();
            for (int i = 0; i < length; i++) {
                if (data.get(i) == null) {
                    continue;
                }
                Game.HeroOneCS.Builder one = Game.HeroOneCS.newBuilder();
                obj.setPlayerID(data.get(i).getPlayerId());
                one.setId(data.get(i).getHeroId());
                one.setLevel(data.get(i).getHeroLevel());
                one.setExp(data.get(i).getHeroExp().intValue());
                one.setIsPlayer(data.get(i).getIsPlayer() == 1 ? true : false);
                one.setStation(data.get(i).getHeroStation());
                one.setStar(data.get(i).getHeroStar());
                one.setIsBattle(data.get(i).getIsBattle() == 1 ? true : false);
                one.setGongExp(data.get(i).getGongExp());

                //英雄吃的药物
                if (null != data.get(i).getMedicineLst() && "" != data.get(i).getMedicineLst()) {
                    String[] medicine = data.get(i).getMedicineLst().split("\\^");
                    for (int j = 0; j < medicine.length; j++) {
                        if ("" == medicine[j]) {
                            continue;
                        }
                        String[] mdis = medicine[j].split(";");
                        if (mdis.length != 2 || "" == mdis[0] || "" == mdis[1]) {
                            continue;
                        }
                        Game.AttrMedicineCs.Builder tempOne = Game.AttrMedicineCs.newBuilder();
                        tempOne.setItemId(Integer.parseInt(mdis[0]));
                        tempOne.setNum(Integer.parseInt(mdis[1]));
                        one.addMedicineLst(tempOne.build());
                    }
                }

                //英雄的装备
                List<Heroitem> items = heroitemCsTool.selectHeroItem(account, data.get(i).getHeroId());
                for (int j = 0; j < items.size(); j++) {
                    if (null == items.get(j)) {
                        continue;
                    }
                    Game.ItemOneCs.Builder item = Game.ItemOneCs.newBuilder();
                    item.setGuid(items.get(j).getGuid());
                    item.setItemId(items.get(j).getItemId());
                    item.setNum(items.get(j).getNum());
                    item.setEnhanceLv(items.get(j).getEnhanceLv());
                    one.addArmLst(item.build());
                }

                //英雄的技能
                List<Heroskill> skills = heroskillCsTool.selectHeroSkill(account, data.get(i).getHeroId());
                for (int j = 0; j < skills.size(); j++) {
                    if (null == skills.get(j)) {
                        continue;
                    }
                    Game.SkillDataCS.Builder skill = Game.SkillDataCS.newBuilder();
                    skill.setId(skills.get(j).getSkillId());
                    skill.setLevel(skills.get(j).getSkillLevel());
                    skill.setIslock(skills.get(j).getSkillLock() == 1 ? true : false);
                    skill.setUsed(skills.get(j).getSkillUsed() == 1 ? true : false);
                    one.addSkillLst(skill.build());
                }

                //英雄的技能
                List<HeroGong> books = heroGongCsTool.selectHeroItem(account, data.get(i).getHeroId());
                for (int j = 0; j < books.size(); j++) {
                    if (null == books.get(j)) {
                        continue;
                    }
                    Game.HeroGongCS.Builder book = Game.HeroGongCS.newBuilder();
                    book.setBookId(books.get(j).getBookId());

                    if (books.get(j).getOpenList() != null) {
                        String[] array = books.get(j).getOpenList().split(";");
                        if (array.length > 0) {
                            for (int k = 0; k < array.length; k++) {
                                String[] array2 = array[k].split(",");
                                if (array2.length == 3) {
                                    Game.AcupointOneCS.Builder skill = Game.AcupointOneCS.newBuilder();
                                    skill.setId(Integer.parseInt(array2[0]));
                                    skill.setIndex(Integer.parseInt(array2[1]));
                                    skill.setLevel(Integer.parseInt(array2[2]));
                                    book.addOpenList(skill);
                                }
                            }
                        }
                    }

                    book.setCurExp(books.get(j).getCurExp());
                    book.setLevel(books.get(j).getLevel());

                    if (books.get(j).getSariraList() != null) {
                        String[] array3 = books.get(j).getSariraList().split(";");
                        for (int k = 0; k < array3.length; k++) {
                            book.addSariraList(Integer.parseInt(array3[k]));
                        }
                    }

                    book.setRate(books.get(j).getRate());
                    book.setUseCount(books.get(j).getUseCount());
                    book.setUnlockYx(books.get(j).getUnlockYx()== 1 ? true : false);
                    book.setIsUse(books.get(j).getIsUse() == 1 ? true : false);
                    book.setOpenYx(books.get(j).getOpenYx() == 1 ? true : false);
                    one.addGongList(book.build());
                }

                obj.addHeros(one);
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_HERO_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Rolespawn数据
    public void handleRolespawnData(String account, MsgEntity msgEntity) throws Exception {
        Game.RoleSpawnCS.Builder obj = Game.RoleSpawnCS.newBuilder();
        obj.setAccount(account);

        List<Rolespawn> data = rolespawnCsTool.selectRoleSpawn(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in rolespawn table!");
        } else {
            Rolespawn act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setMapId(act.getMapId());
            obj.setX(act.getX());
            obj.setY(act.getY());
            obj.setZ(act.getZ());
            obj.setLastMapId(act.getLastMapId());
            obj.setLastMapPosx(act.getLastMapPosx());
            obj.setLastMapPosy(act.getLastMapPosy());
            obj.setLastMapPosz(act.getLastMapPosz());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_ROLESPAWN_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取ShopRefresh数据
    public void handleShopRefreshData(String account, MsgEntity msgEntity) throws Exception {
        Game.ShopRefreshCs.Builder obj = Game.ShopRefreshCs.newBuilder();
        obj.setAccount(account);

        List<Shoprefresh> data = shoprefreshCsTool.selectShopRefresh(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in shoprefresh table!");
        } else {
            Shoprefresh act = data.get(0);
            obj.setPlayerID(act.getPlayerId());

            //商店一
            if (null != act.getShopOne() && "" != act.getShopOne()) {

                String[] shopOne = act.getShopOne().split("\\^");
                for (int i = 0; i < shopOne.length; i++) {
                    if ("" == shopOne[i]) {
                        continue;
                    }

                    String[] datas = shopOne[i].split(";");
                    if (datas.length != 4 || "" == datas[0] || "" == datas[1] || "" == datas[2] || "" == datas[3]) {
                        continue;
                    }

                    Game.ShopOneCs.Builder one = Game.ShopOneCs.newBuilder();
                    one.setId(Integer.parseInt(datas[0]));
                    one.setCount(Integer.parseInt(datas[1]));
                    one.setSale(Integer.parseInt(datas[2]));
                    one.setSoldout(Integer.parseInt(datas[3]));
                    obj.addShopOneLst(one.build());
                }
            }

            //商店二
            if (null != act.getShopTwo() && "" != act.getShopTwo()) {
                String[] shopTwo = act.getShopTwo().split("\\^");
                for (int i = 0; i < shopTwo.length; i++) {
                    if ("" == shopTwo[i]) {
                        continue;
                    }

                    String[] datas = shopTwo[i].split(";");
                    if (datas.length != 4 || "" == datas[0] || "" == datas[1] || "" == datas[2] || "" == datas[3]) {
                        continue;
                    }

                    Game.ShopOneCs.Builder one = Game.ShopOneCs.newBuilder();
                    one.setId(Integer.parseInt(datas[0]));
                    one.setCount(Integer.parseInt(datas[1]));
                    one.setSale(Integer.parseInt(datas[2]));
                    one.setSoldout(Integer.parseInt(datas[3]));
                    obj.addShopTwoLst(one.build());
                }
            }
            obj.setOneRefresh(act.getOneRefresh());
            obj.setTwoRefresh(act.getTwoRefresh());

            //副本链
            if (null != act.getChipBatLst() && "" != act.getChipBatLst()) {

                String[] chips = act.getChipBatLst().split("\\^");
                for (int i = 0; i < chips.length; i++) {
                    if ("" == chips[i]) {
                        continue;
                    }

                    String[] datas = chips[i].split(";");
                    if (datas.length != 4 || "" == datas[0] || "" == datas[1] || "" == datas[2] || "" == datas[3]) {
                        continue;
                    }

                    Game.ChipBattleOneCs.Builder one = Game.ChipBattleOneCs.newBuilder();
                    one.setId(Integer.parseInt(datas[0]));
                    one.setChance(Integer.parseInt(datas[1]));
                    one.setRefresh(Integer.parseInt(datas[2]));
                    one.setOver(Integer.parseInt(datas[3]));
                    obj.addChipBatLst(one.build());
                }
            }

            obj.setLastDieTime(act.getLastDieTime());
            obj.setSpawnInterval(act.getSpawnInterval().intValue());

            //侠客岛
            if (null != act.getHeroIslandLst() && "" != act.getHeroIslandLst()) {
                String[] heros = act.getHeroIslandLst().split(";");
                if (heros.length == 4 && "" != heros[0] && "" != heros[1] && "" != heros[2] && "" != heros[3]) {

                    Game.HeroIslandOneCs.Builder one = Game.HeroIslandOneCs.newBuilder();
                    one.setResetTime(Integer.parseInt(heros[0]));
                    one.setTopLevel(Integer.parseInt(heros[1]));
                    one.setCurrentLevel(Integer.parseInt(heros[2]));
                    one.setGetBoxId(Integer.parseInt(heros[3]));
                    obj.setHeroIslandLst(one.build());
                }
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_SHOPREFRESH_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Tasklist数据
    public void handleTasklistData(String account, MsgEntity msgEntity) throws Exception {
        Game.TaskListCS.Builder obj = Game.TaskListCS.newBuilder();
        obj.setAccount(account);

        List<Tasklist> data = tasklistCsTool.selectTask(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in tasklist table!");
        } else {
            Tasklist act = data.get(0);

            obj.setPlayerID(act.getPlayerId());
            obj.setIdentify(act.getIdentify());
            for (int i = 0; i < data.size(); i++) {
                if (null == data.get(i)) {
                    continue;
                }

                Game.TaskCS.Builder task = Game.TaskCS.newBuilder();
                task.setIdentify(data.get(i).getIdentify());
                task.setCurrentTask(data.get(i).getCurrentTask());

                if (null != data.get(i).getSchedule() && "" != data.get(i).getSchedule()) {
                    String[] temps = data.get(i).getSchedule().split("\\^");
                    for (int j = 0; j < temps.length; j++) {
                        if ("" == temps[j]) {
                            continue;
                        }
                        String[] mdis = temps[j].split(";");
                        if (mdis.length != 3 || "" == mdis[0] || "" == mdis[1] || "" == mdis[2]) {
                            continue;
                        }

                        Game.TaskScheduleOneCS.Builder tempOne = Game.TaskScheduleOneCS.newBuilder();
                        tempOne.setId(Integer.parseInt(mdis[0]));
                        tempOne.setHaveCount(Integer.parseInt(mdis[1]));
                        tempOne.setCount(Integer.parseInt(mdis[2]));
                        task.addSchedule(tempOne.build());
                    }
                }

                if (null != data.get(i).getFinishTask() && "" != data.get(i).getFinishTask()) {

                    String[] finishs = data.get(i).getFinishTask().split("\\^");
                    for (int j = 0; j < finishs.length; j++) {
                        if ("" == finishs[j]) {
                            continue;
                        }

                        task.addFinishTask(Integer.parseInt(finishs[j]));
                    }
                }

                task.setTotalCount(data.get(i).getTotalCount());
                task.setTodayCount(data.get(i).getTodayCount());

                if (data.get(i).getType() == 1) {
                    //主线任务
                    obj.setMainTask(task.build());
                } else if (data.get(i).getType() == 2) {
                    //悬赏任务
                    obj.setRewardTask(task.build());
                } else if (data.get(i).getType() == 3) {
                    //酒馆侠客任务
                    obj.addPubTask(task.build());
                }
            }
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_TASKLIST_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取Purgatory数据
    public void handlePurgatoryData(String account, MsgEntity msgEntity) throws Exception {
        Game.PurgatoryCs.Builder map = Game.PurgatoryCs.newBuilder();
        map.setAccount(account);

        List<Purgatory> data = purgatoryCsTool.selectPurgatory(account);
        if (data.size() == 0) {

            map.setPlayerID("");
            map.setAccount(account);
            //map.
        } else {
            Purgatory act = data.get(0);

            map.setPlayerID(act.getPlayerId());
            map.setAccount(act.getAccount());
            //商店一
            if (null != act.getShopOneLst() && "" != act.getShopOneLst()) {

                String[] shopOne = act.getShopOneLst().split("\\^");
                for (int i = 0; i < shopOne.length; i++) {
                    if ("" == shopOne[i]) {
                        continue;
                    }

                    String[] datas = shopOne[i].split(";");
                    if (datas.length != 4 || "" == datas[0] || "" == datas[1] || "" == datas[2] || "" == datas[3]) {
                        continue;
                    }

                    Game.ShopOneCs.Builder one = Game.ShopOneCs.newBuilder();
                    one.setId(Integer.parseInt(datas[0]));
                    one.setCount(Integer.parseInt(datas[1]));
                    one.setSale(Integer.parseInt(datas[2]));
                    one.setSoldout(Integer.parseInt(datas[3]));
                    map.addShopOneLst(one.build());
                }
            }

            map.setOneRefresh(act.getOneRefresh());
            map.setLastDieTime(act.getLastDieTime());
            map.setSpawnInterval(act.getSpawnInterval());
            map.setCurrentMap(act.getCurrentMap());
            map.setTotalOrder(act.getTotalOrder());
            map.setCurrentStar(act.getCurrentStar());
            map.setLastRefreshNum(act.getLastRefreshNum());
            map.setBatRefresh(act.getBatRefresh());
            if (act.getOneCs() != null) {
                String[] temp = act.getOneCs().split(";");
                if (temp.length == 2) {
                    Game.PurgatoryOneCS.Builder one = Game.PurgatoryOneCS.newBuilder();
                    one.setLastDieTime(Long.parseLong(temp[0]));
                    one.setSpawnInterval(Integer.parseInt(temp[1]));
                    map.setOneCS(one);
                } else {
                    Game.PurgatoryOneCS.Builder one = Game.PurgatoryOneCS.newBuilder();
                    one.setLastDieTime(0);
                    one.setSpawnInterval(0);
                    map.setOneCS(one);
                }
            }

            if (act.getCompareItem() != null) {
                String[] temp = act.getCompareItem().split(";");
                for (int i = 0; i < temp.length; i++) {
                    if ("" != temp[i]) {
                        String[] temp2 = temp[i].split("\\*");
                        Game.AwardAttr.Builder one = Game.AwardAttr.newBuilder();
                        one.setId(Integer.parseInt(temp2[0]));
                        one.setCount(Integer.parseInt(temp2[1]));
                        map.addCompareItem(one);
                    }

                }
            }

            map.setFreeRefresh(act.getFreeRefresh());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_PURGATORY_DOWNLOAD_RES, 99, 0, map.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //处理ios充值
    public void handleIOSPurchaseyData(String account, MsgEntity msgEntity) throws Exception {
        Game.FuckIosCS.Builder obj = Game.FuckIosCS.newBuilder();
        obj.setAccount(account);

        List<Fuckios> data = fuckiosCsTool.selectIosItem(account);
        if (data.size() == 0) {
            logger.error("Account:" + account + "not exist in iospurchase table!");
        } else {
            String account2 = "";
            String playerid2 = "";

            int length = data.size();
            for (int i = 0; i < length; i++) {
                if (null == data.get(i)) {
                    continue;
                }

                if(account2 == "")
                {
                    account2 = data.get(i).getAccount();
                }

                if(playerid2 == "")
                {
                    playerid2 = data.get(i).getPlayerId();
                }


                Game.FuckIosOneCS.Builder one = Game.FuckIosOneCS.newBuilder();

                one.setItemId(data.get(i).getItemId());
                one.setProductId(data.get(i).getProductId());
                one.setStatus(data.get(i).getStatus());
                one.setBid(data.get(i).getBid());
                one.setBvrs(data.get(i).getBvrs());
                one.setUniqueIdentifier(data.get(i).getUniqueIdentifier());
                one.setOriginalTransactionId(data.get(i).getOriginalTransactionId());
                one.setTransactionId(data.get(i).getTransactionId());
                one.setOriginalPurchaseDatePst(data.get(i).getOriginalPurchaseDatePst());
                one.setPurchaseDatePst(data.get(i).getPurchaseDatePst());
                one.setOriginalPurchaseDateMs(data.get(i).getOriginalPurchaseDateMs());
                one.setPurchaseDateMs(data.get(i).getPurchaseDateMs());
                one.setOriginalPurchaseDate(data.get(i).getOriginalPurchaseDate());
                one.setPurchaseDate(data.get(i).getPurchaseDate());
                one.setUniqueVendorIdentifier(data.get(i).getUniqueVendorIdentifier());
                one.setQuantity(data.get(i).getQuantity());
                one.setVersionExternalIdentifier(data.get(i).getVersionExternalIdentifier());

                obj.addList(one.build());
            }
            obj.setAccount(account2);
            obj.setAccount(playerid2);
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_IOSPURCHASE_DOWNLOAD_RES, 99, 0, obj.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }

    //提取GrowUpWelf数据
    public void handleGrowupwelfData(String account, MsgEntity msgEntity) throws Exception {
        Game.GrowUpWelfCs.Builder map = Game.GrowUpWelfCs.newBuilder();
        map.setAccount(account);

        List<Growupwelf> data = growupwelfCsTool.selectGrowupwelf(account);
        if (data.size() == 0) {

            map.setPlayerID("");
            map.setAccount(account);
            map.setFlag(0);
            map.setLv5(0);
            map.setLv10(0);
            map.setLv15(0);
            map.setLv20(0);
            map.setLv25(0);
            map.setLv30(0);
            map.setLv35(0);
            map.setLv40(0);
            map.setLv45(0);
            map.setLv50(0);
            map.setLv55(0);
            map.setLv60(0);
            map.setLv70(0);
        } else {
            Growupwelf act = data.get(0);

            map.setPlayerID(act.getPlayerId());
            map.setAccount(act.getAccount());
            map.setFlag(act.getFlag());
            map.setLv5(act.getLv5());
            map.setLv10(act.getLv10());
            map.setLv15(act.getLv15());
            map.setLv20(act.getLv20());
            map.setLv25(act.getLv25());
            map.setLv30(act.getLv30());
            map.setLv35(act.getLv35());
            map.setLv40(act.getLv40());
            map.setLv45(act.getLv45());
            map.setLv50(act.getLv50());
            map.setLv55(act.getLv55());
            map.setLv60(act.getLv60());
            map.setLv70(act.getLv70());
        }

        MsgEntity resRt = gameUtilTool.getReferResult(msgEntity.getChannel(), Cmdcode.SaveCmdCode.CS_GROWUPWELF_DOWNLOAD_RES, 99, 0, map.build().toByteArray());
        msgEntity.getChannel().writeAndFlush(resRt);// 发送消息
    }


    //反序列化登录请求
    public static Cmdcode.LoginReqCs loginSerialBytes2Object(byte[] bytes) {
        try {
            return Cmdcode.LoginReqCs.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        return null;
    }

    //反序列化注册请求
    public static Cmdcode.RegisterReqCs registerSerialBytes2Object(byte[] bytes) {
        try {
            return Cmdcode.RegisterReqCs.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        return null;
    }

    //反序列化普通请求
    public static Cmdcode.CommonReqCs commonSerialBytes2Object(byte[] bytes) {
        try {
            return Cmdcode.CommonReqCs.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        return null;
    }
}

